#pragma once

#include "ValueSpecificationAction.h"

#include "OutputPin.h"
#include "ValueSpecification.h"

namespace uml {

ValueSpecificationAction::ValueSpecificationAction(const QString& umlType)
    : Action(umlType) {}

void ValueSpecificationAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    result_ = JsonSerializable::create<OutputPin>(json.value("result"), errorList);

    value_ = JsonSerializable::create<ValueSpecification>(json.value("value"), errorList);

}

void ValueSpecificationAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (result_) {
        QJsonObject result_json;
        result_->toJson(result_json);
        json.insert("result", result_json);
    }
    if (value_) {
        QJsonObject value_json;
        value_->toJson(value_json);
        json.insert("value", value_json);
    }
}

/// <summary>
/// result getter
/// The OutputPin on which the result value is placed.
/// </summary>
shared_ptr<OutputPin> ValueSpecificationAction::result() const {
    return result_;
}

/// <summary>
/// result setter
/// The OutputPin on which the result value is placed.
/// </summary>
void ValueSpecificationAction::setResult(shared_ptr<OutputPin> value) {
    result_ = value;
}

/// <summary>
/// value getter
/// The ValueSpecification to be evaluated.
/// </summary>
shared_ptr<ValueSpecification> ValueSpecificationAction::value() const {
    return value_;
}

/// <summary>
/// value setter
/// The ValueSpecification to be evaluated.
/// </summary>
void ValueSpecificationAction::setValue(shared_ptr<ValueSpecification> value) {
    value_ = value;
}

} // namespace uml
